package part1.api.map;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class MapTest {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",97);
        map.put("英语",96);
        map.put("物理",99);
        Set<String> keySet = map.keySet();
        for (String s : keySet){
            System.out.println(s);
        }
        System.out.println("----------");

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        Iterator<Map.Entry<String,Integer>> iterator = entrySet.iterator();
        while (iterator.hasNext()){
            Map.Entry<String,Integer> entry = iterator.next();
            System.out.println(entry.getKey()+":"+entry.getValue());
        }

        System.out.println("---------");

        Collection<Integer> values =  map.values();
        for (Integer value : values){
            System.out.println(value);
        }

        System.out.println("forEach遍历");

        keySet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        keySet.forEach(s -> System.out.println(s));
        keySet.forEach(System.out::println);

        entrySet.forEach(new Consumer<Map.Entry<String, Integer>>() {
            @Override
            public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
                System.out.println(stringIntegerEntry.getKey());
            }
        });

        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+integer);
            }
        });
        map.forEach((key,value) -> System.out.println(key+":"+value));

    }
}
